Create a proper MSBuild ToolTask based VSTestTask - #2702
Create a proper MSBuild ToolTask based VSTestTask#2702microsoft-github-policy-service[bot] merged 27 commits into
Conversation
commented
Feb 6, 2021
|
Please note that I would be happy to answer any questions and/or reservations, and/or discuss any suggestions or improvements on this PR. |
commented
Feb 6, 2021
|
Thank you for the contribution Mac (@mcartoixa), I'll check this during the week and ask my questions, if any. |
commented
Feb 6, 2021
|
/azp run |
commented
Feb 6, 2021
|
Azure Pipelines successfully started running 1 pipeline(s). |
569e421 to
cefe13d
Compare
|
I just rebased this PR against the |
|
|
||
| activeProcess.WaitForExit(); | ||
| Tracing.Trace("VSTest: Exit code: " + activeProcess.ExitCode); | ||
| return activeProcess.ExitCode == 0; |
There was a problem hiding this comment.
We should only return !Log.HasLoggedErrors. The task should fail if and only if it has logged any errors.
There was a problem hiding this comment.
I believe this is the way it's usually done in MSBuild tasks. Does vstest.console.exe return an error code even in cases of success?
Anyway this task is a copy (mostly left unchanged) of the current one, kept here for compatibility purposes. The goal of this PR is rather to introduce a new task that would be more respectful of MSBuild, see VSTestTask (the diff is rather useless on that one, though).
|
|
||
| if (!string.IsNullOrEmpty(this.VSTestFramework)) | ||
| { | ||
| Console.WriteLine(Resources.TestRunningSummary, this.TestFileFullPath, this.VSTestFramework); |
There was a problem hiding this comment.
A task shouldn't use Console.WriteLine, but instead use Log.LogMessage:
https://source.dot.net/#Microsoft.Build.Tasks.Core/Copy.cs,255
There was a problem hiding this comment.
Agreed in general, but this has been left unchanged for compatibility with current behavior. The goal of this PR is rather to introduce a new task that would be more respectful of MSBuild, see VSTestTask.
| // Avoid logging "Task returned false but did not log an error." on test failure, because we don't | ||
| // write MSBuild error. https://github.com/dotnet/msbuild/blob/51a1071f8871e0c93afbaf1b2ac2c9e59c7b6491/src/Framework/IBuildEngine7.cs#L12 | ||
| var allowfailureWithoutError = BuildEngine.GetType().GetProperty("AllowFailureWithoutError"); | ||
| allowfailureWithoutError?.SetValue(BuildEngine, true); |
There was a problem hiding this comment.
we should really not do this. If there was an error, log an MSBuild error. If there wasn't an error, don't log it.
Let's remove this reflection logic.
There was a problem hiding this comment.
This has been left unchanged for compatibility with current behavior. The goal of this PR is rather to introduce a new task that would be more respectful of MSBuild, see VSTestTask.
commented
Jun 30, 2021
|
Just to make it clear to me. The |
commented
Jun 30, 2021
|
MarkKharitonov Right. |
cefe13d to
7acb932
Compare
commented
Oct 24, 2021
|
Just rebased again against |
commented
Feb 8, 2022
|
When can we expect some kind of decision about the future of this PR? As mentioned before quite a few bugs could be affected by this.
|
7acb932 to
b6dcdc8
Compare
|
It took me 2 days to set up a new barely working development environment, but I think I managed to rebase this PR against |
d1e30d4 to
1b4b548
Compare
commented
Jun 9, 2022
|
Any update on the status of this request? |
commented
Jun 28, 2022
|
nit: file should be renamed too! test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs -> VSTestTaskTests.cs |
commented
Jun 28, 2022
|
Nirmal Guru (@Nirmal4G) Thanks for the review! There is nothing more that I would like than having a discussion with the owners. Meanwhile it seems that I will have to rebase this PR again... |
Description
Update from nohwnd:
A new task VSTestTask2 and a logger MSBuildLogger (for internal use only) was added. And can be enabled by setting
/p:VsTestUseMSBuildOutput=true.This is not enabled anywhere by default, neither in dotnet test, or under vstest, because I want to collect some feedback first.
The current console forwarding task has been renamed VSTestForwardingTask. The new VSTestTask, based on ToolTask, properly integrates into the MSBuild framework.
If the
$(VSTestUseConsole)property is set toTrueduring the build, the old console forwarding VSTestForwardTask is used: logs are lost but output is colorized (like today). Otherwise the new VSTestTask is used: logs are fine but colorization is lost (except for errors, that are properly recognized by MSBuild).A new PR will be submitted right away on the dotnet/sdk project so that
dotnet testsets the$(VSTestUseConsole)property.In effect:
dotnet test(like today).dotnet msbuild -Target:VSTest.This PR feels more like a workaround than a proper fix: it still feels weird to depend on a MSBuild task (VSTestForwardingTask) that is not entirely MSBuild friendly... But it seems like the easiest fix that is compatible with the old behavior.
A proper fix would probably center around the implementation of
dotnet testwhich could calldotnet exec vstest.console.dlldirectly (in addition to MSBuild, for the build part only). This would render current workarounds like for dotnet/msbuild#3130, orAllowFailureWithoutErrordefinitely obsolete.Related issue
Fixes (or at least gives an option around) #680, #1503, #2224, dotnet/sdk#9481, dotnet/msbuild#5387 and probably more...
This is a new attempt after #2437.